package hyl.core;

import java.nio.charset.Charset;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import hyl.core.conf.MyConfig;
import hyl.core.conf.MyConst;
import hyl.core.conf.MyLang;
import hyl.core.run.MyRun;
import hyl.core.run.MyTimer;

public class AIni {
	public static final Logger Log = LoggerFactory.getLogger("Aini");
//规定:所有程序只能用UTF-8编码,防止乱码
	public final static String Charset = MyCharset.UTF8;
	public final static Charset charset = MyCharset._UTF8;
	public static final boolean ISDEBUG = true;

	/* 0 未知 1window 2 linux */
	public static int OS = 0;
	static {
		String s = System.getProperty("os.name");
		if (s.toLowerCase().contains("window"))
			OS = 1;
		else
			OS = 0;

		//MyConfig.ini();
		MyLang.getInstance();
		MyConst.getInstance();
	}

	private static MyRun _mrun = null;

	public static MyRun getMyRun() {
		if (_mrun == null)
			_mrun = MyRun.getInstance("核心", 8);
		return _mrun;
	}

	public static String getUpdateFile() {
		if (!MyFun.isEmpty(MyConfig._config.UPDATEFILE)) {

			return MyConfig.loadTxt(MyConfig._config.UPDATEFILE);

		}
		return null;
	}

	// 系统关闭时的事件触发的退出事件
	protected static Runnable onExit;

	public static MyTimer createMyTimer() {
		return MyTimer.getInstance();
	}

	public static void closeAllThreads() {
		MyRun.closeAll();
		Log.info("所有线程池都已关闭");
		MyTimer.closeAll();
		Log.info("所有定时线程都已关闭");
	}

	public static String getConst(String key) {
		return MyConst.getInstance().get(key);
	}

	public synchronized static String getLang(String key) {
		return MyLang.getInstance().get(key);
	}
}
